<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/css/styleslogin.css">
<div class="modal fade" id="loginModal" role="dialog"
	aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<!-- start -->
		<div class="jq22-container" style="padding-top: 10px">
			<div class="login-wrap">
				<div class="login-html">
					<input id="tab-1" type="radio" name="tab" class="sign-in" checked>
						<label for="tab-1" class="tab">登录</label> 
					<input id="tab-2" type="radio" name="tab" class="sign-up">
						<label for="tab-2" class="tab">注册</label>
					<div class="login-form">
						<div class="foot-lnk">
							<label id="result" for="tab-1"></label>
						</div>
						<div class="sign-in-htm">

							<form method="post">
								<div class="group">
									<label for="user" class="label">用户名</label> <input
										id="userName" type="text" class="input">
								</div>
								<div class="group">
									<label for="pass" class="label">密码</label> <input id="userPass"
										type="password" class="input" data-type="password">
								</div>
								<div class="hr"></div>
							</form>
							<div class="group">
								<button class="button" onclick="login()">登录</button>
							</div>
						</div>


						<div class="sign-up-htm">
							<form method="post">
								<div class="group">
									<label for="user" class="label">用户名</label> <input id="regname"
										type="text" class="input">
								</div>
								<div class="group">
									<label for="pass" class="label">密码</label> <input id="regpass"
										type="password" class="input" data-type="password">
								</div>
								<div class="group">
									<label for="pass" class="label">重复密码</label> <input
										id="regpass2" type="password" class="input"
										data-type="password">
								</div>
								<div class="hr"></div>
							</form>
							<div class="group">
								<button class="button" onclick="register()">注册</button>
							</div>

						</div>
					</div>
				</div>
			</div>
		</div>
		<!-- end -->
	</div>
</div>
<script type="text/javascript">
	function login() {

		var userName = $("#userName").val();
		var userPass = $("#userPass").val();

		$.post(getContextPath() + "/user/login", {
			userName : userName,
			userPass : userPass
		}, function(result) {
			if (result.login == "yes") {
				window.location.href=getContextPath()+"/index";
			} else {
				$("#result").html("账号或密码不正确");
			}

		});

	}

	function register() {

		var userName = $("#regname").val();
		var userPass = $("#regpass").val();
		var userPass2 = $("#regpass2").val();
		
		$.post(getContextPath()+"/user/register",{
			userName:userName,
			userPass:userPass,
			userPass2:userPass2
			},function(result){
				if(result.reg =="yes"){
					$("#result").html("注册成功");
				}else if(result.reg=="diff"){
					$("#result").html("两次输入的密码不一致");
				}
			}
				
		);

	}
</script>